package com.yst.sqlbuilder;


import java.util.ArrayList;
import java.util.List;

public class SQLSafe {
    public interface IVerify{
        boolean verify(String value);
    }

    public static class ExceptionSQLNotSafe extends RuntimeException{
        public ExceptionSQLNotSafe(String message) {
            super("SQL value not safe:"+message);
        }
    }

    private final static List<IVerify> chainVerify=new ArrayList<>();

    private final static SQLSafe instance=new SQLSafe();

    static {

    }
    public static SQLSafe getInstance(){
        return instance;
    }

    public SQLSafe register(IVerify verify){
        if (!chainVerify.contains(verify)){
            chainVerify.add(verify);
        }
        return this;
    }

    public SQLSafe unRegister(IVerify verify){
        chainVerify.remove(verify);
        return this;
    }

    public void checkValue(String value){
        for(IVerify verify:chainVerify){
            if (!verify.verify(value)){
                throw new ExceptionSQLNotSafe(value);
            }
        }
    }


}
